# coding:utf-8


import socket;

from multiprocessing import Process
# from  socket import  socket,AF_INET

HTML_ROOT_DIR = ""
webcontent = "hello itcast"
    # 处理客户端请求
    # 获取客户端请求数据
def handle_client(args):
    client_socket = args;
    print("inter handle client");
    print(client_socket);
    request_data = client_socket.recv(1024);
    #print request_data;
    #构造响应数据
    response_start_line = "HTTP/1.1 200 OK\r\n"
    response_headers = "Server: My server\r\n"
    response_body = webcontent
    response = response_start_line+response_headers+"\r\n"+response_body
    #print "response data:"+response
    #向客户端返回数据
    client_socket.send(response)

    # client_socket.send(bytes(response,"utf-8"))
    #关闭用户连接
    client_socket.close()

if __name__ == "__main__":
    server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    # server_socket.bind("",8000);
    server_socket.bind(('', 8082))

    print(server_socket);
    server_socket.listen(128);

    while True:
        print("1")
        client_socket,client_address = server_socket.accept();
        print (client_address);
        if client_socket and client_address:
            print("进入 if 语句")

            print ("=====")

            print ("=====")
            handle_client_process = Process(target=handle_client,args=(client_socket,))
            handle_client_process.start();
            client_socket.close();








































